package com.lixixi.tingshu.album;

import io.minio.*;
import io.minio.errors.MinioException;

import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

public class FileUploadExample {
	public static void main(String[] args) throws IOException, NoSuchAlgorithmException, InvalidKeyException {
		try
		{
			// Create a minioClient with the MinIO server playground, its access key and secret key.
			MinioClient minioClient =
					MinioClient.builder()
							.endpoint("minioUrl")
							.credentials("accessKey", "secretKey")
							.build();

			// Make 'asiatrip' bucket if not exist.
			boolean found =
					minioClient.bucketExists(BucketExistsArgs.builder().bucket("bucketName").build());
			if (!found)
			{
				// Make a new bucket called 'asiatrip'.
				minioClient.makeBucket(MakeBucketArgs.builder().bucket("bucketName").build());
			} else
			{
				System.out.println("Bucket 'bucketName' already exists.");
			}

			// Upload "C:\\Users\\xiaoyi132\\Pictures\\Saved Pictures\\beauty.png" as object name 'beauty.png' to bucket
			// 'asiatrip'.
			// Upload known sized input stream.
//			minioClient.putObject(
//					PutObjectArgs.builder().bucket("bucketName").object("my-objectname").stream(
//									inputStream, size, -1)
//							.contentType("video/mp4")
//							.build());

//			minioClient.uploadObject(
//					UploadObjectArgs.builder()
//							.bucket("asiatrip")
//							.object("beauty.png")
//							.build());
			System.out.println(
					"'/home/user/Photos/asiaphotos.zip' is successfully uploaded as "
							+ "object 'asiaphotos-2015.zip' to bucket 'asiatrip'.");
		} catch (MinioException e)
		{
			System.out.println("Error occurred: " + e);
			System.out.println("HTTP trace: " + e.httpTrace());
		}
	}
}


